package zhoug.map.location;



import zhoug.common.json.GsonUtils;

import java.io.Serializable;

import androidx.annotation.Keep;

/**
 * 自定义位置实体
 * @Author HK-LJJ
 * @Date 2019/12/27
 * @Description
 */
@Keep
public class ZLocation implements Serializable {
    /**
     * 定位类型
     */
    public static final int TypeGps = 101;//GPS定位
    public static final int TypeNetWork = 102;//网络定位
    public static final int TypeCache = 103;//缓存定位

    private int type = 0;//定位类型
    private ZAddress address;//地址
    private double latitude;//纬度
    private double longitude;//经度
    private State state = State.Idle;//状态


    public enum State implements Serializable{
        Idle,//无状态
        FAIL,//定位失败
        SUCCESS,//定位成功
    }

    public ZLocation() {
    }

    /**
     * copy
     *
     * @param location
     * @return
     */
    public static ZLocation copy(ZLocation location) {
        ZLocation newLocation = new ZLocation();
        newLocation.setType(location.getType())
                .setAddress(location.getAddress())
                .setLatLng(location.getLatitude(), location.getLongitude())
                .setState(location.getState());
        return newLocation;
    }

    /**
     * 把source的信息复制到target中
     * @param target
     * @param source
     */
    public static void copy(ZLocation target, ZLocation source) {
        target.setType(source.getType())
                .setAddress(source.getAddress())
                .setLatLng(source.getLatitude(), source.getLongitude())
                .setState(source.getState());
    }

    public State getState() {
        return state;
    }

    public ZLocation setState(State state) {
        this.state = state;
        return this;
    }

    public ZAddress getAddress() {
        return address;
    }

    public ZLocation setAddress(ZAddress address) {
        this.address = address;
        return this;
    }

    public double getLatitude() {
        return latitude;
    }

    public ZLocation setLatLng(double latitude, double longitude) {
        this.latitude = latitude;
        this.longitude = longitude;
        return this;
    }

    public double getLongitude() {
        return longitude;
    }


    public String getAddressStr() {
        return address != null ? address.address : null;
    }

    public int getType() {
        return type;
    }

    public ZLocation setType(int type) {
        this.type = type;
        return this;
    }

    @Override
    public String toString() {
        return GsonUtils.getDefault().toJson(this);
    }

}
